<?php

define('URL', 'http://192.168.8.61/'); //定义名为URL的常量
define('URL_AVATAR', URL . 'upload/images/avatar/'); //定义头像文件的URL
define('URL_CIRCLE', URL . 'upload/images/circle/'); //定义头像文件的URL

function output_data($date)
{
    header('Content-Type: application/json; charset=UTF-8');
    $newData = array();
    $newData['code'] = 1;
    $newData['msg'] = 'success';
    $newData['data'] = $date;
    //json_encode 将数据格式化为json字符串
    echo json_encode($newData);
    die();
}

function output_error($msg)
{
    header('Content-Type: application/json; charset=UTF-8');
    $array = array();
    $array['code'] = 2;
    $array['msg'] = $msg;
    $array['data'] = '';
    echo json_encode($array);
    die();
}

function get_ip_address($ip)
{
    $url = 'http://whois.pconline.com.cn/ipJson.jsp?ip=' . $ip . '&json=true';
    $ch = curl_init($url);
    $header = array('content-type: application/x-www-form-urlencoded; charset=UTF-8');
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);
    curl_close($ch);
    $json = json_decode(mb_convert_encoding($result, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5'), true);
    return $json['addr'];
}
